﻿/***
*
*travel common js
*
*douzhengyang
*
*2013-5-21
*
***/
$(document).ready(function() {
    $('li.btn_subNav').hover(function() {
        var offset = $(this).offset();
        var offsetW = offset.left;
        var offsetH = offset.top;
        //alert(offsetH);
        $(this).addClass('selected');
        $('.sub-nav').css({ "left": offsetW - 50, "top": offsetH + 50 });
        $('.sub-nav').show();
        $('.sub-nav').hover(function() { $(this).show(); $('li.btn_subNav').addClass('selected'); }, function() { $(this).hide(); $('li.btn_subNav').removeClass('selected'); })
    }, function() { $('.sub-nav').hide(); $(this).removeClass('selected'); })

    var len = $("#idNum > li").length;

    var index = 0;

    $("#idNum li").mouseover(function() {
        index = $("#idNum li").index(this);
        showImg(index);
    });
    $('#idTransformView').hover(function() {
        if (MyTime) {
            clearInterval(MyTime);
        }
    }, function() {
        MyTime = setInterval(function() {
            showImg(index)
            index++;
            if (index == len) { index = 0; }
        }, 4000);
    });
    var MyTime = setInterval(function() {
        showImg(index)
        index++;
        if (index == len) { index = 0; }
    }, 4000);

    $fDropDown($('.readMore a'));
    
    $('img.image1').data('ad-desc', 'Whoa! This description is set through elm.data("ad-desc") instead of using the longdesc attribute.<br>And it contains <strong>H</strong>ow <strong>T</strong>o <strong>M</strong>eet <strong>L</strong>adies... <em>What?</em> That aint what HTML stands for? Man...');
    $('img.image1').data('ad-title', 'Title through $.data');
    $('img.image4').data('ad-desc', 'This image is wider than the wrapper, so it has been scaled down');
    $('img.image5').data('ad-desc', 'This image is higher than the wrapper, so it has been scaled down');
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
          galleries[0].settings.effect = $(this).val();
          return false;
      });
    $('#toggle-slideshow').click(
      function() {
          galleries[0].slideshow.toggle();
          return false;
      });
    $('#toggle-description').click(
      function() {
          if (!galleries[0].settings.description_wrapper) {
              galleries[0].settings.description_wrapper = $('#descriptions');
          } else {
              galleries[0].settings.description_wrapper = false;
          }
          return false;
      });
});
function showImg(i) {
    $("#idSlider").stop(true, false).animate({ top: -320 * i }, 800);
    $("#idNum li")
    .eq(i).addClass("on")
    .siblings().removeClass("on");
}
function $fDropDown(links) {
    links.each(function() {
        //var $firstPara = visiblePara;
        var visiblePara = $(this).parent().prev('div');
        var paraHeight = visiblePara.height();

        if (paraHeight > 55) { visiblePara.height(55); } else { $(this).hide() }
        $(this).click(function() {
            visiblePara.height(paraHeight)
            //$(this).parent().parent().children('br:gt(1)').slideToggle('slow');
            var $link = $(this);
            if ($link.text() == "查看更多▼") {
                $link.text('收起▲');
            } else {
                $link.text('查看更多▼');
                visiblePara.height(55)
            }
            return false;
        });
    })
}
//common msg alert
var PageAlert = function() {
    function msg_alert(data) {
        alert(data);
    }
    return {
        msg: msg_alert
    }
} ();
//parmes valid
function tallme_valid() {
    var UNAME = $("#ctl00_ContentPlaceHolder1_userName");
    var UPHONE = $("#ctl00_ContentPlaceHolder1_phoneNo");
    if (UNAME.val().length <= 0) {
        PageAlert.msg('请输入用户名');
        return false;
    }
    if (UPHONE.val().length <= 0) {
        PageAlert.msg('请输入电话');
        return false;
    }
    var myreg = /^1(([3][456789])|([5][01789])|([8][678]))[0-9]{8}$/;
    if (!myreg.test(UPHONE.val())) {
        PageAlert.msg('请输入正确的电话号码');
        return false;
    }
    return true;
}


function navigate(this_pager) {
    $("#nav ul li").each(function() {
        var $this_obj = $(this);
        var each_id = $this_obj.attr("id");
        if (each_id.length > 0 && each_id != "player") {
            if (each_id == this_pager)
                $this_obj.attr("class", "selected");
            else
                $this_obj.removeAttr("class");
        }
    });
}

function LinkToLandscape()
{
     //get project name
    $.getJSON("/helper/get_xmlb_id", { Name: $(this).attr("title") }, function (data)
    {
        window.location.href = "/jingqu/index/" + data;
    });
}